package com.eleadmin.ocean.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.ocean.entity.OceanBulkCargoFee;
import com.eleadmin.ocean.service.OceanBulkCargoFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 海运散货运费
 * @author : Doman
 * @date : 2023-11-06 15:38:47
 * @version ：1.0
 */

@Api(tags = "海运散货运费")
@RestController
@RequestMapping("/api/ocean/oceanBulkCargoFee")
public class OceanBulkCargoFeeController extends BaseController {

    @Autowired
    private OceanBulkCargoFeeService oceanBulkCargoFeeService;

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:list')")
    //@ApiOperation("分页查询海运散货运费")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, OceanBulkCargoFee oceanBulkCargoFee) throws Exception{
        return oceanBulkCargoFeeService.list(page, oceanBulkCargoFee, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:list')")
    //@ApiOperation("查询全部海运散货运费")
    @GetMapping()
    public JsonResult list(OceanBulkCargoFee oceanBulkCargoFee){
        return oceanBulkCargoFeeService.list(oceanBulkCargoFee, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:list')")
    //@ApiOperation("根据id查询海运散货运费")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return oceanBulkCargoFeeService.getById(id);
    }


    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:save')")
    @OperationLog
    @ApiOperation(value ="添加海运散货运费")
    @PostMapping()
    public JsonResult save(@RequestBody OceanBulkCargoFee oceanBulkCargoFee) {
        try {
            return oceanBulkCargoFeeService.save(oceanBulkCargoFee, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:update')")
    @OperationLog
    @ApiOperation(value ="修改海运散货运费")
    @PutMapping()
    public JsonResult update(@RequestBody OceanBulkCargoFee oceanBulkCargoFee) {
        try {
            return oceanBulkCargoFeeService.update(oceanBulkCargoFee, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoFee:remove')")
    @OperationLog
    @ApiOperation(value ="删除海运散货运费")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return oceanBulkCargoFeeService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
